package edu.hebtu.controller;

import edu.hebtu.mapper.impl.AdminMapper;
import edu.hebtu.mapper.impl.CarMapper;
import edu.hebtu.mapper.impl.UserMapper;
import edu.hebtu.pojo.Admin;
import edu.hebtu.pojo.Car;
import edu.hebtu.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class ViewDeletedInformationController {

    private final UserMapper userMapper;
    private final AdminMapper adminMapper;
    private final CarMapper carMapper;

    @Autowired
    public ViewDeletedInformationController(UserMapper userMapper, AdminMapper adminMapper, CarMapper carMapper) {
        this.userMapper = userMapper;
        this.adminMapper = adminMapper;
        this.carMapper = carMapper;
    }

    @RequestMapping("/deleted_user")
    public String deleted_user(Model model) {

        List<User> users = userMapper.findDeleted();

        users.removeIf(aValue -> aValue.getUserType() == 1);        //移除教练

        model.addAttribute("users", users);

        return "deleted/deleted-user";
    }

    @RequestMapping("/deleted_trainer")
    public String deleted_trainer(Model model) {

        List<User> users = userMapper.findDeleted();

        users.removeIf(aValue -> aValue.getUserType() == 0);        //移除学员

        model.addAttribute("users", users);

        return "deleted/deleted-trainer";
    }

    @RequestMapping("/deleted_admin")
    public String deleted_admin(Model model) {

        List<Admin> admins = adminMapper.findDeleted();

        model.addAttribute("admins", admins);

        return "deleted/deleted-admin";
    }

    @RequestMapping("/deleted_car")
    public String deleted_car(Model model) {

        List<Car> cars = carMapper.findDeleted();

        model.addAttribute("cars", cars);

        return "deleted/deleted-car";
    }

}
